<template>
  <el-row>
    <el-col :span="12">
      <el-table :data="list">
        <el-table-column label="编码" prop="coding" />
        <el-table-column label="名称" prop="name" />
        <el-table-column label>
          <template v-slot:header="scope">
            <el-button size="mini">所有</el-button>
          </template>
          <template v-slot="scope">
            <i class="el-icon-s-marketing" @click="reading(scope.row.id)" />
          </template>
        </el-table-column>
      </el-table>
    </el-col>
    <el-col :span="12">
      <ve-line :data="chartData" />
    </el-col>
  </el-row>
</template>

<script>
import API from '../../../api/asset/parameter'
import VeLine from 'v-charts/lib/line'
export default {
  name: 'EquipmentParameter',
  components: { VeLine },
  props: {
    value: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      list: [],
      redingList: []
    }
  },
  computed: {
    chartData() {
      const chart = {
        columns: ['日期', '值'],
        rows: []
      }
      chart.rows = this.redingList.map(item => {
        return { '日期': item.datetime, '值': item.value }
      })
      return chart
    }
  },
  watch: {
    value() {
      this.index()
    }
  },
  created() {
    this.index()
  },
  methods: {
    index() {
      API.index({ equipment_id: this.value }).then(response => {
        this.list = response.data.list
      })
    },
    reading(id) {
      API.reading(id).then(response => {
        this.redingList = response.data.data
      })
    }
  }
}
</script>

<style>
</style>
